package util;

import java.util.ArrayList;
import org.json.simple.*;
import org.json.simple.parser.*;

public class JSONConverter {

	public static ArrayList<ArrayList<String>> parse(String json) {
		ArrayList <String> answer = new ArrayList <String>();
		ArrayList <String> docID = new ArrayList <String>();
		
		JSONParser parser = new JSONParser();
		Object obj;
		try {
			obj = parser.parse(json);
			JSONObject jsonObj = (JSONObject) obj;
			jsonObj = (JSONObject) jsonObj.get("d");
			JSONArray results = (JSONArray) jsonObj.get("results");
			for(int i = 0;i<results.size();i++) {
				jsonObj = (JSONObject) results.get(i);
				answer.add((String) jsonObj.get("Description"));
				docID.add((String) jsonObj.get("Url"));
			}
			ArrayList<ArrayList<String>> res = new ArrayList<ArrayList<String>>();
			res.add(answer);
			res.add(docID);
			return res;
		} catch (ParseException e) {
			System.out.println("Fallo al parsear");
			return null;
		}
	}
}
